import { LoveTaskGiveItem } from "./LoveTaskGiveItem";
import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { RadioButtonGroup } from "../../../../../fl/controls/RadioButtonGroup";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { LoveTaskGiveItemInfo } from "../../../model/loveTask/LoveTaskGiveItemInfo";
//class LoveTaskGiveList
    
    export  class LoveTaskGiveList /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        protected onSelectedChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as LoveTaskGiveItem;
            if (loc1) 
            {
                if (loc1.selected) 
                {
                    if (this._lastSelected && !(this._lastSelected == loc1) && this._lastSelected.selected) 
                    {
                        this._lastSelected.selected = false;
                    }
                    this._lastSelected = loc1;
                }
                else if (this._lastSelected == loc1) 
                {
                    this._lastSelected = null;
                }
            }
            return;
        }

        /* internal  */initUI(): void
        {
            this._itemList = new GBox();
            this._itemList.x = 5;
            this._itemList.y = 5;
            this._itemList.direction = GBoxDirection.VERTICAL;
            addChild(this._itemList);
            this._radioGroup = new RadioButtonGroup("LoveTaskGiveItemRadio");
            return;
        }

        public updateData(arg1: Array<any>): void
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            var loc2=arg1.length;
            while (loc1 < loc2) 
            {
                loc4 = arg1[loc1];
                (loc3 = ObjectPool.getObject(LoveTaskGiveItem)).updateData(loc4);
                loc3.addEventListener(flash.events.Event.CHANGE, this.onSelectedChangeHandler);
                this._itemList.addChild(loc3);
                ++loc1;
            }
            this._itemList.invalidate();
            this._lastSelected = this._itemList.getChildAt(0) as LoveTaskGiveItem;
            this._lastSelected.selected = true;
            return;
        }

        public dispose(): void
        {
            var loc1=null;
            while (this._itemList.numChildren > 0) 
            {
                loc1 = this._itemList.getChildAt(0) as LoveTaskGiveItem;
                loc1.dispose();
                loc1.removeEventListener(flash.events.Event.CHANGE, this.onSelectedChangeHandler);
                ObjectPool.disposeObject(loc1, LoveTaskGiveItem);
                this._itemList.removeChild(loc1);
            }
            return;
        }

        public get selectedData(): LoveTaskGiveItemInfo
        {
            if (this._lastSelected && this._lastSelected.selected) 
            {
                return this._lastSelected.data as LoveTaskGiveItemInfo;
            }
            return null;
        }

        public /* override */ get height(): number
        {
            return this._itemList.height;
        }

        /* internal */ /* var */_itemList: GBox;

        /* internal */ /* var */_radioGroup: RadioButtonGroup;

        /* internal */ /* var */_lastSelected: LoveTaskGiveItem;
    }
